﻿using AllInServiceAuthorization;
using Cmp.Web.Common;
using Cmp.Web.IService;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Server.HttpSys;
using SqlSugar.Extensions;
using System.Text.Json.Serialization;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Cmp.Web.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DeptController : ControllerBase
    {
        private readonly IDeptService _deptService;
        private ExceptionAll errMsg;
        public DeptController(IDeptService deptService)
        {
            _deptService = deptService;
        }
        [HttpGet]
        [Authorize(Roles = "Administrator")]
        public ActionResult GetDeptInfo()
        {
            var result = _deptService.GetDeptInfoList(out errMsg).Result;
            if (errMsg != null)
            {
                return new MJsonResult(errMsg.errMsgId.ObjToInt(), errMsg.errMsg, result).GetResult();
            }
            else
            {
                return new MJsonResult(0, "", result).GetResult();
            }
        }
    }
}
